//undetermined :1、首次授权，未确定是否可使用此权限，此时调用对应的API时系统会弹出提示框让用户确认  
//authorized:	之前同意了授权
//denied:	之前拒绝了权限
//denied_always:	之前拒绝了权限
//none:	无此权限
//error:出错
const H5Permission = {
	names:{
		PUSH:'',
		LOCATION:'LOCATION',
		RECORD:'RECORD',
		CAMERA:'CAMERA',
		ALBUM:'',//scope.album
		CALLPHONE:'',
		CONTACT:'',
		CALENDAR:'',
		MEMO:''
	},
	// 获取设备的录音权限
	record(resolve, reject) {
		if (typeof navigator.mediaDevices === 'undefined' || !navigator.mediaDevices.getUserMedia) {
			return reject('denied');
		}
		navigator.mediaDevices.getUserMedia({
			audio: isEdge ? true : { echoCancellation: false }
		}).then(function(mic) {
			resolve('authorized');
		}).catch(function(error) {
			reject('none');
		})
	},
	camera(resolve, reject) {
		if (typeof navigator.mediaDevices === 'undefined' || !navigator.mediaDevices.getUserMedia) {
			return reject('denied');
		}
		navigator.mediaDevices.getUserMedia({
			video: true
		}).then(function(video) {
			resolve('authorized');
		}).catch(function(error) {
			reject('none');
		});
	},
	location(resolve, reject) {
		if (typeof navigator.geolocation === 'undefined' || !navigator.geolocation) {
			return reject('denied');
		}

		navigator.geolocation.getCurrentPosition(
			function(position){
			   resolve('authorized');
			},
			function(error){
				switch (error.code) {
					case error.PERMISSION_DENIED:
						reject('denied');
						break;
					case error.POSITION_UNAVAILABLE:
						reject('error',{code:error.POSITION_UNAVAILABLE,message:'定位服务不可用'});
						break;
					case error.TIMEOUT:
						reject('error',{code:error.TIMEOUT,message:'定位超时'});
						break;
					case error.UNKNOWN_ERROR:
						reject('error',{code:error.UNKNOWN_ERROR,message:'未知错误'});
						break;
            }
		});

	},
	check(permissionID) {
		var permissionIdentity = permissionID.toUpperCase();
		return new Promise((resolve, reject) => {
			switch (permissionIdentity) {
				case "LOCATION":
					this.location(resolve, reject);
					break;
				case "RECORD":
					this.record(resolve, reject);
					break;
				case "CAMERA":
					this.camera(resolve, reject);
					break;
				default:
					resolve('none');
					break;
			}
		});
	},
	request(permissionID) {
		return new Promise((resolve, reject) => {
			resolve('none');
		});
	},	
	setting(permissionID='') {
		
	}
}
export default H5Permission;